package com.demo.springcloud.controller;

import com.demo.springcloud.entity.Payment;
import com.demo.springcloud.entity.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author hxg
 * @version 1.0
 * @date 2021/12/23 23:36
 */
@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {
    //提供者是集群模式的，订单访问地址通过微服务名称访问
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/payment/save")
    public R<Payment> create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/save", payment, R.class);
    }

    @GetMapping("/payment/get/{id}")
    public R<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/"+id, R.class);
    }
    @GetMapping("/payment/zipkin")
    public R<Payment> getPaymentZipkin() {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/zipkin", R.class);
    }

}
